package il.ac.braude.sona.gui.mytables;

import il.ac.braude.sona.control.MainController;
import il.ac.braude.sona.control.ViewRequestController;
import il.ac.braude.sona.entities.Messege;
import il.ac.braude.sona.gui.list_table.ListTableClickAdapter;
import il.ac.braude.sona.gui.list_table.ListTableFrame;

import java.util.ArrayList;

import javax.swing.JOptionPane;

/**
 * GUI class to determines messages form frames.
 * @author  Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenthal
 * Group 6,<br>Laboratory in Software Engineering,Ort Braude College.</p>
 *
 */
@SuppressWarnings("serial")
public class MessegeTableFrame  extends ListTableFrame<Messege> {

	public ArrayList<Messege> toDelete=new ArrayList<Messege>();
	static String[] options = {"Cancel", "Open request","Delete this message"};

	/**
	 * Makes the massage frame.
	 * @param messeges Messages to show.
	 * @param table  modle columns needed to show message.
	 */
	public MessegeTableFrame(String messeges, ArrayList<Messege> table) {
		super(messeges,table);
		listTable.addListTableClickListener(new ListTableClickAdapter<Messege>() {
			@Override
			public void onDoubleClick(Messege t) {
				int reply = JOptionPane.showOptionDialog(null, "Message related to R.ID "+t.getRid()+":\n"+t.getMssg(),"Message View",0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
				if (reply == 2)
				{
					new Thread(MainController.deleteMssg(t)).run();
					JOptionPane.showMessageDialog(null,"Message will remove from inbox");

				}
				if (reply == 1)
				{
					new ViewRequestController().viewReqFromMssg(t.getRid());
				}
				dispose();
			}
		});


	}


}